<template>
    <div class="app-container">
        <!-- <PageHeader :border="false" title="执行警务登记"/> -->
        <el-form ref="queryParamsRef" :inline="true" :model="queryParams">
            <el-row>
                <el-col :span="8">
                    <el-form-item label="派警类型">
                        <el-select v-model="queryParams.recordType" clearable style="width:300px"
                            @change="getendPoliceregisterLists">
                            <el-option v-for="item in filteredSendPoliceType" :key="item.value" :label="item.label"
                                :value="item.value" />
                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="时间起止" label-width="100px">
                        <el-date-picker v-model="searchTime" type="daterange" range-separator="-"
                            start-placeholder="开始时间" end-placeholder="截止时间" value-format="YYYY-MM-DD"
                            @change="changeDateTimerHandle" style="width:300px" />
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item>
                        <el-button type="primary" @click="getendPoliceregisterLists">
                            <el-icon class="me-1">
                                <Search />
                            </el-icon>
                            查询
                        </el-button>
                    </el-form-item>
                    <el-form-item>
                        <el-button @click="handleRest(queryParamsRef)">
                            <el-icon class="me-1">
                                <Refresh />
                            </el-icon>
                            重置
                        </el-button>
                    </el-form-item>
                </el-col>
            </el-row>
        </el-form>
        <el-divider class="mt-0" />
        <el-table ref="SendPoliceTableRef" v-loading="loading" :data="SendPoliceTable"
            @selectionChange="selectChangeHandle"
            @row-dblclick="handleRowDblClick"
            stripe
            :row-style="tableRowStyle"
            show-overflow-tooltip border>
            <el-table-column label="申请单位" prop="unitName" />
            <el-table-column label="用警部门" prop="depName" />
            <el-table-column label="派警类型" prop="type" />
            <el-table-column label="任务区分项一" prop="taskName" />
            <el-table-column label="任务区分项二" prop="taskName2" />
            <el-table-column label="用警时间" prop="" />
            <el-table-column fixed="right" label="操作" width="80">
                <template #default="scope">
                    <el-button link size="small" type="primary"
                        @click="AddRegisterRef.showEditUsePoliAppl(scope.row, '执行警务登记', '6')">
                        <el-icon class="me-1">
                            <Edit />
                        </el-icon>
                        登记
                    </el-button>
                </template>
            </el-table-column>
        </el-table>
        <pagination v-show="total > 0" v-model:limit="paging.pageSize" v-model:page="paging.pageNum" :total="total"
            @pagination="getendPoliceregisterLists" />

        <!-- 用的就是派警申请的组件 只是组件名变了-->
        <AddEditSendPoliAppl ref="AddRegisterRef" @getUserPoliApplList="getendPoliceregisterLists" />
    </div>

</template>

<script setup>
import PageHeader from "@/components/PageHeader/index.vue";
import { ElMessageBox } from 'element-plus'

import AddEditSendPoliAppl from "@/components/UserPoli/UserPoli.vue";

import { SendPoliceregisterList } from "@/api/SendPolice/SendPolice";

import { getCurrentInstance } from "vue";
import PageEnum from "@/enum/PageEnum.js";

const { proxy } = getCurrentInstance();
const { nj_sendpolice_type, nj_anjian_status } = proxy.useDict('nj_sendpolice_type', 'nj_anjian_status')
// 计算属性过滤字典数据
const filteredSendPoliceType = computed(() => {
    return nj_sendpolice_type.value.filter(item => item.value == 2 || item.value == 3);
});
const queryParamsRef = ref()
const deleteStatus = ref(true)
const AddRegisterRef = ref({})
const loading = ref(false)
const searchTime = ref([])
const paging = ref({
    // 页码
    pageNum: 1,
    // 分页数量
    pageSize: PageEnum.SIZE
})
const queryParams = ref({})

const total = ref(0)
const SendPoliceTable = ref([])

onMounted(() => {
    getendPoliceregisterLists()
})
// 斑马纹样式函数
const tableRowStyle = ({ row, rowIndex }) => {
    if (rowIndex % 2 === 0) {
        return { backgroundColor: '#e6ecff' }; // 偶数行背景色
    }
    return {}; // 奇数行默认透明
}
// 获取调解室房间列表
const getendPoliceregisterLists = async () => {
    loading.value = true
    await SendPoliceregisterList(queryParams.value, paging.value).then(res => {
        SendPoliceTable.value = res.rows
        total.value = res.total
        loading.value = false
    })
}
const selectChangeHandle = (data) => {
    deleteStatus.value = data.length === 0;
}
const handleRowDblClick = (row) => {
    AddRegisterRef.value.showEditUsePoliAppl(row, '执行警务登记', '6')
}
// 改变时间
const changeDateTimerHandle = (date) => {
    if (date) {
        queryParams.value = {
            ...queryParams.value,
            params: {
                beginTime: date[0],
                endTime: date[1]
            }
        }
    } else {
        queryParams.value = {
            ...queryParams.value,
            params: {
                beginTime: '',
                endTime: ''
            }
        }
    }
    getendPoliceregisterLists()
}
// 重置搜索调解
const handleRest = (formEl) => {
    queryParams.value = {
    }
    getendPoliceregisterLists()
}
</script>

<style lang="scss" scoped>
/* 保留斑马纹的同时添加悬停效果 */
:deep().el-table--striped .el-table__body tr.el-table__row--striped:hover td {
  background-color: #a5b8f4; /* 悬停时的红色 */
}

:deep().el-table__body tr:hover td {
  background-color: #a5b8f4; /* 悬停时的红色 */
}</style>